package owlapps2012.base;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.reasoner.InconsistentOntologyException;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;

public abstract class FactsClassifier 
{

	private static Log log = LogFactory.getLog(FactsClassifier.class);
	
	protected OWLReasoner reasoner;
	protected OWLReasonerFactory reasonerFactory;
	
	protected FactsImport importModule;
	protected OWLOntology owlToClassify;

	
//	public void init()
//	{
//		
//	}
	
	public FactsClassifier(OWLReasonerFactory reasonerFactory, FactsImport importModule)
	{
		this.reasonerFactory = reasonerFactory;
		this.importModule = importModule;
	}
	
	public void start() throws Exception
	{
		int count = 0;
		while(true)
		{	
			owlToClassify = importModule.prepareOWL();
			if(owlToClassify != null)
			{	
				classify();
				doAfter();
				count++;
			}
			else
			{
				if(count==0)
					log.warn("No facts has been retrieved...");
				else	
					log.info("Classified "+count+" owl files. No more facts to classify...");
				break;
			}
		}
	}
	
	protected abstract void classify();
	
	//for examample saving OWL file or dropping results to a database - an OWLOntologyMAnager can be obtained using owlToClassify.getOWLOntologyManager()
	protected abstract void doAfter();
	
		
//	private void classify()
//	{
//		reasoner = reasonerFactory.createReasoner(owlToClassify);
//        reasoner.precomputeInferences();
//        if(!reasoner.isConsistent())
//        {
//        	throw new InconsistentOntologyException();
//        }
//	}
	
}
